<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>分配菜单</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<input id="roleId" type="hidden" value="${ roleId }"/>
  	
  	<div class="mini-splitter" style="width: 100%; height: 100%;" borderStyle="border:0;">
  		<div size="120" showCollapseButton="true" minSize="100" maxSize="150">
	    	<ul id="menuTree" class="mini-tree" url="rp/system/baseData/menuMng/getAllMenus?show=1"
	    		style="width:100%;height:100%;" 
			    showTreeIcon="true" textField="title" 
			    idField="id" resultAsTree="false"
			    onnodeclick="menuTreeNodeClick"> 
			</ul>
	    </div>
	    <div showCollapseButton="false">
	    	<div style="width:100%;">
		        <div class="mini-toolbar" style="padding:1px;border-top:0;border-left:0;border-right:0;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                    	<a class="mini-button" onclick="selectAll()">全选</a>
		                    	<a class="mini-button" onclick="unselectAll()">清除选中</a>
		                       	<a class="mini-button" onclick="ok()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
		                    </td>
		                    <td style="white-space:nowrap;">
		                        
		                    </td>
		                </tr>
		            </table>           
		        </div>
		    </div>
	    	<div class="mini-fit">
		  		<ul id="menuItemTree" class="mini-tree" url="" style="width:100%; height:100%;" 
			        showTreeIcon="true" textField="text" idField="id" parentField="pid" resultAsTree="false"  
			        showCheckBox="true" checkRecursive="false" 
			        allowSelect="false" enableHotTrack="false"
			        autoCheckParent="false">
			    </ul>
		  	</div>
	    </div>
  	</div>
  	
  	
  	
  	
     
  	
  	
	<script type="text/javascript">
		
		var menuItemTree;
		var menuTree;
		var roleId;
	
		$(function(){
			mini.parse();

			menuItemTree = mini.get("menuItemTree");
			menuTree = mini.get("menuTree");
			roleId = $("#roleId").val();
			
		});
		
		function menuTreeNodeClick(e){
			var node = e.node;
			menuItemTree.load("rp/system/baseData/menuMng/getMenuItemsByEnabled?menuId="+node.id);
			menuItemTree.expandAll();
			rp_ajax("rp/system/roleMng/getRoleOwnMenuItems", {roleId:roleId, menuId:node.id}, function(result){
				if(result){
					menuItemTree.setValue(result);
				}
			});
		}
		
		function selectAll(){
            var nodes = menuItemTree.getAllChildNodes(menuItemTree.getRootNode());
            menuItemTree.checkNodes(nodes);
        }
		
        function unselectAll() {
            var nodes = menuItemTree.getAllChildNodes(menuItemTree.getRootNode());
            menuItemTree.uncheckNodes(nodes);
        }
		
		function ok(){
			var menuId = menuTree.getSelectedNode().id;
            var menuItemIds = menuItemTree.getValue();
            rp_ajax("rp/system/roleMng/updateRoleMenus", 
            	{roleId:roleId, menuId:menuId, menuItemIds:menuItemIds}, function(result){
	            if(result == "success"){
		            mini.alert("保存成功");
	            }
            });
		}
	</script>
  </body>
</html>
